from tool import *
import json


def upload_oss(local_path, oss_path):
    print("upload_oss , oss_path ", oss_path)
    print("upload_oss , local_path ", local_path)
    command = "~/ossutilmac64 cp -r -u {} {}".format(local_path, oss_path)
    call_command(command)
    result = "OSS ：\n {} \n {}".format(local_path, oss_path)
    return result


def get_last_version(project_type, platform, version) -> dict:
    # oss://faramita/vr-ota/AssetBundle/MetaNew/Pico/3.0.0/ResConfig.json
    local_path = "../AssetBundles/OSS/{}/{}/{}/ResConfig.json".format(project_type, platform, version)
    rmFile(local_path)
    command = "~/ossutilmac64 cp oss://faramita/vr-ota/AssetBundle/MetaNew/{}/{}/{}/ResConfig.json {}" \
        .format(project_type, platform, version, local_path)
    call_command(command)
    result = read_file(local_path)
    if not result:
        return None
    config_dict = json.loads(result)
    return config_dict


def get_resversion_config(project_type, platform, version, ResVersion) -> dict:
    # oss://faramita/vr-ota/AssetBundle/MetaNew/Pico/3.0.0/1/ResConfig.json
    local_path = "../AssetBundles/OSS/{}/{}/{}/{}/ResConfig.json" \
        .format(project_type, platform, version, ResVersion)
    rmFile(local_path)
    command = "~/ossutilmac64 cp oss://faramita/vr-ota/AssetBundle/MetaNew/{}/{}/{}/{}/ResConfig.json {}" \
        .format(project_type, platform, version, ResVersion, local_path)
    call_command(command)
    result = read_file(local_path)
    if not result:
        return None
    config_dict = json.loads(result)
    return config_dict
